﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace 图书管理系统
{
    public partial class 赔书 : Form
    {
        public 赔书()
        {
            InitializeComponent();
        }

        private void 赔书_Load(object sender, EventArgs e)
        {

            User user = 用户登录.user;
            textBox1.Text = user.Name;
            if(textBox1.Text==null)
            {
                MessageBox.Show("请登录！");
                this.Close();
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            User user = 用户登录.user;
            if (textBox1.Text!=""&&textBox2.Text!=""&&textBox3.Text!="")
            {
                BookDao bookDao = new BookDao();
                int judge = bookDao.judge(textBox2.Text, textBox3.Text);
                if (judge==1)
                {
                    if (comboBox1.SelectedItem.ToString() == "赔书")
                    {
                        ClaimrecordDao claimrecordDao = new ClaimrecordDao();

                        claimrecordDao.insert(user.Id, textBox3.Text,textBox4.Text);
                        MessageBox.Show("提交申请成功！");
                    }
                    else
                    {
                        PenaltyrecordDao penaltyrecordDao = new PenaltyrecordDao();
                        penaltyrecordDao.insert(user.Id, textBox3.Text);
                    }
                }
                else if(judge==0)
                {
                    MessageBox.Show("书名和索书号不匹配！");
                }
                else
                {
                    MessageBox.Show("书名或索书号不正确，无此图书！");
                }
            }
            else
            {
                MessageBox.Show("信息请填写完整！请登录");
            }    
        }

        private void button2_Click(object sender, EventArgs e)
        {          
            this.Close();
            User user = 用户登录.user;
            首页 form2 = new 首页(user);
            form2.Show();
        }

        private void label5_Click(object sender, EventArgs e)
        {

        }
    }
}
